package com.sr.controller;

import com.sr.constant.Constant;
import com.sr.util.R;
import com.sr.util.ToolUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xiaochi
 * @date 2022/5/4 11:18
 * @desc CaptchaController
 */
@Api(tags = "后台接口 -> 验证码")
@RestController
@RequestMapping(Constant.Api.BACK_PREFIX)
public class CaptchaController extends BaseController{

    @ApiOperation(value = "获取验证码",notes = "获取验证码")
    @GetMapping("/captcha")
    public R<Map<String,String>> captcha(){
        String code = ToolUtil.getRandomString(4);
        this.getRequest().getSession().setAttribute(Constant.BACK_CAPTCHA_CODE,code);
        Map<String,String> map = new HashMap<>();
        map.put("code",code);
        return R.ok(map);
    }
}
